#pragma once
#include <map>

#include "../BondMarketStream.h"
#include "../bondlib.h"

class S_BONDLIB_EXPORT CTakenPriceMap {
  struct ClearPrice {
    char m_price[12];  // 收益率
    time_t m_time;
  };
  struct TakenPrice {
    double price;            // 净价
    double yield;            // 收益率
    double clean_price_div;  // 净价偏离度
    double yield_div;        // 收益率偏离度
    int exec;                // 0行权，1到期，-1不限
    time_t time;             // 成交时间
  };
  typedef std::map<BrokerKey, TakenPrice> PriceMap;
  typedef std::map<BrokerKey, ClearPrice> ClearPriceMap;
  typedef std::map<BrokerKey, ClearPrice> YieldPriceMap;
  PriceMap m_prices;
  ClearPriceMap m_clear_prices;
  YieldPriceMap m_yield_prices;
  double m_min_value;
  bool m_with_yieldstr;

 public:
  CTakenPriceMap();
  void SetWithYieldStr(bool withYieldStr) { m_with_yieldstr = withYieldStr; }
  double GetMinValue() const { return m_min_value; }
  void Clear();
  void SetMap(int ncorpid, bool withString = false);
  const char* GetClearPriceStr(const BrokerKey& key);
  const char* GetYeildStr(const BrokerKey& key);
  double GetCleanPrice(const BrokerKey& key, bool bBestQuotePage = false,
                       bool bAscend = true);
  double GetYield(const BrokerKey& key);
  double GetCleanPriceDiv(const BrokerKey& key);
  double GetYieldDiv(const BrokerKey& key);
  int GetExec(const BrokerKey& key);
  bool SetTakenPrice(const MarketStreamInfo& msi, bool withString);

 public:
  double GetYieldCalc(const BrokerKey& key);

 private:
  TakenPrice* GetLastTaken(const BrokerKey& key);
};